package com.zone.mybatis.binding;

import com.zone.mybatis.mapping.MappedStatement;
import com.zone.mybatis.mapping.SqlCommandType;
import com.zone.mybatis.session.Configuration;
import com.zone.mybatis.session.SqlSession;

import java.lang.reflect.Method;

/**
 * @author: zongzi
 * @description: TODO
 * @date: 2023/12/20
 */
public class MapperMethod {
    private String msId;

    private SqlCommandType sqlCommandType;

    public MapperMethod(Class<?> mapperInterface, Method method, Configuration configuration) {
        String msId = String.format("%s.%s", mapperInterface.getName(), method.getName());
        MappedStatement mappedStatement = configuration.getMappedStatement(msId);

        this.msId = mappedStatement.getMsId();
        this.sqlCommandType = mappedStatement.getSqlCommandType();
    }

    public Object execute(SqlSession sqlSession, Object[] args) {
        switch (sqlCommandType) {
            case INSERT:
                break;
            case UPDATE:
                break;
            case DELETE:
                break;
            case SELECT:
                return sqlSession.selectOne(msId, args);
        }
        return null;
    }
}
